package com.br.mytho.components.gui;

import java.awt.FlowLayout;
import java.util.List;

import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class ComboBox<E> extends JPanel {
	private static final long serialVersionUID = 1L;
	
	private FlowLayout layout = new FlowLayout(FlowLayout.LEADING, 5, 5);
	
	private JComboBox<E> combo = null;
	private JLabel label = null;
	
	public ComboBox() {
		this(null, null);
	}
	
	public ComboBox(String label) {
		this(label, null);
	}
	
	public ComboBox(List<E> items) {
		this(null, items);
	}
	
	public ComboBox(String label, List<E> items) {
		super();
		this.setLayout(layout);
		
		if (label != null) {
			this.label = new JLabel(label);
			this.add(this.label);
		}
		
		combo = new JComboBox<E>();
		
		if (items != null) {
			this.addItems(items);
		}
		this.add(this.combo);
	}
	
	public ComboBox<E> addItems(List<E> items) {
		for (E item : items) {
			this.combo.addItem(item);
		}
		return this;
	}
	
}
